import request from "@/utils/request"; // utils/request.js
import { Loading } from "element-ui";

export async function req(
  method = "post",
  url = "",
  data = {},
  isLoading = true
) {
  const _method = method.toLowerCase();

  //加载loading
  const loadingInstance = Loading.service({
    fullscreen: true,
    text: "Loading",
    spinner: "el-icon-loading",
    background: "rgba(0, 0, 0, 0.7)",
  });

  if (_method == "get" || _method == "delete") {
    var res = await request({
      baseURL: process.env.VUE_APP_BASE_API,
      url,
      method: _method,
    });
  }

  if (_method == "post" || _method == "put") {
    var res = await request({
      baseURL: process.env.VUE_APP_BASE_API,
      url,
      method: _method,
      data,
    });
  }

  //关闭loading
  loadingInstance.close();

  return res;
}
